package com.puman.beautyfarmcounselor.ui.task.view;


import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ListView;

import com.puman.beautyfarmcounselor.ui.task.model.BaseEntity;


/**
 */
public class ExpendListViewCompat extends ExpandableListView {

	private static final String TAG = "curry";

	private SlideView mFocusedItemView;

	public ExpendListViewCompat(Context context) {
		super(context);
	}

	public ExpendListViewCompat(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ExpendListViewCompat(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public void shrinkListItem(int position) {
		View item = getChildAt(position);

		if (item != null) {
			try {
				((SlideView) item).shrink();
			} catch (ClassCastException e) {
				e.printStackTrace();
			}
		}
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
//		Log.i("curry", "ExpendListViewCompat event.getAction()："+event.getAction());
		switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN: {
				int x = (int) event.getX();
				int y = (int) event.getY();
				int position = pointToPosition(x, y);
				Log.e(TAG, "postion=" + position);
				if (position != INVALID_POSITION) {
					try {
						BaseEntity data = (BaseEntity) getItemAtPosition(position);
						mFocusedItemView = data.slideView;
						Log.e(TAG, data + ":FocusedItemView=" + mFocusedItemView);
					} catch (Exception e) {
						e.printStackTrace();
						break;
					}

				}
			}
			default:
				break;
		}

		if (mFocusedItemView != null) {
			mFocusedItemView.onRequireTouchEvent(event);
		}else{
			Log.i("curry", "ExpendListViewCompat mFocusedItemView == null");
		}
		return super.onTouchEvent(event);
	}

}
